package com.kingbright.testlibgdx.utils;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class Utils
{
    public static class Image
    {
        /**
         * this method will draw image in the middle of the screen, keeping the
         * ratio of width and height
         * 
         * @param batch
         *            the @SpriteBatch to draw
         * @param texture
         *            the @Texture to be drawn
         */
        public static void drawInMiddle(SpriteBatch batch, Texture texture)
        {
            float ratio = Math.max((float) texture.getWidth()
                    / (float) Gdx.graphics.getWidth(),
                    (float) texture.getHeight()
                            / (float) Gdx.graphics.getHeight());
            float x = 0;
            float y = 0;
            float width = 0;
            float height = 0;
            if (ratio > 1.0)
            {
                width = texture.getWidth() / ratio;
                height = texture.getHeight() / ratio;
            }
            x = (Gdx.graphics.getWidth() - width) / 2;
            y = (Gdx.graphics.getHeight() - height) / 2;
            batch.draw(texture, x, y, width, height);
        }
    }
}
